home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / libsrc~1.z / libsrc~1 / system.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-28  |  1016 b   |  47 lines

  1. /*  system.c
  2.  *
  3.  *  Changed to return() on fork failure, added signal()
  4.  *  calls.          Terrence W. Holm      Oct. 1988
  5.  *
  6.  *
  7.  * Adjusted last arg to execl (it should be a NULL pointer not zero)
  8.  * Adjusted type if sig*
  9.  *    ++jrb
  10.  */
  11.  
  12. #include "lib.h"
  13. #include <stdio.h>
  14. #include <signal.h>
  15. #include <sys/wait.h>
  16.  
  17. int system(cmd)
  18. _CONST char *cmd;
  19. {
  20.     int retstat, procid, waitstat;
  21. #ifdef __STDC__
  22.     void (*sigint)(), (*sigquit)();
  23. #else
  24.     int (*sigint)(), (*sigquit)();
  25. #endif
  26.  
  27.     if ( (procid = fork()) == 0) {
  28.     /* Child does an exec of the command. */
  29.         execl( "/bin/sh", "sh", "-c", cmd, (char *)NULL );
  30.         exit( 127 );
  31.     }
  32.  
  33.     /* Check to see if fork failed. */
  34.     if (procid < 0) return( 127 << 8 );
  35.  
  36.     sigint  = signal( SIGINT,  SIG_IGN );
  37.     sigquit = signal( SIGQUIT, SIG_IGN );
  38.  
  39.     while ( (waitstat = wait(&retstat)) != procid && waitstat != -1 ) ;
  40.     if (waitstat == -1) retstat = -1;
  41.  
  42.     signal( SIGINT,  sigint );
  43.     signal( SIGQUIT, sigquit );
  44.  
  45.     return(retstat);
  46. }
  47.